package com.snail.snailvr.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.text.TextUtils;

import java.io.File;
import java.net.URI;


public class PackageInfoUtil {
    private static String TAG = PackageInfoUtil.class.getSimpleName();

    public static PackageInfo getPackageInfoByName(Context context, String pkgName) {
        PackageInfo packageInfo = null;
        if (context != null && pkgName != null) {
            try {
                //getPackageInfo第二个参数传0表示只获取该包名下的ApplicationInfo信息，
                //传-1表示获取AndroidManifest中配置的所有内容
                packageInfo = context.getPackageManager().getPackageInfo(pkgName, 0);
            } catch (Exception ignore) {
            }
        }
        return packageInfo;
    }

    public static boolean deleteApkFromDiskByUri(String filePath) {
        if (TextUtils.isEmpty(filePath)) {

            return false;
        }
        File file = new File(URI.create(filePath));
        if (file.exists()) {
            if (file.delete()) {
                return true;
            }
        }
        return false;
    }
}
